<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<!--终止生产-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-stop">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">生产令终止</h4>
            </div>
            <div class="modal-body">
                <form id="stopForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="prodStoRea" class="col-sm-2 control-label no-padding-right">终止原因</label>
                        <div class="col-sm-10">
                            <input name="prodId" type="hidden" style="display: none"/>
                            <textarea id="prodStoRea" class="form-control" name="prodStoRea" maxlength="500"
                                      style="resize: none" rows="9" cols="60"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn_stop">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--暂缓-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-postponement">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">生产令暂缓</h4>
            </div>
            <div class="modal-body">
                <form id="postponementForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="prodRem" class="col-sm-2 control-label no-padding-right">备注</label>
                        <div class="col-sm-10">
                            <input name="prodId" type="hidden" style="display: none"/>
                            <textarea id="prodRem" class="form-control" name="prodRem" maxlength="500"
                                      style="resize: none" rows="9" cols="60"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn_postponement">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>下料任务维护</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none"
                                     style="margin-left:0px;margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        生产令编号
                                    </label>
                                    <label class="control-label">
                                        <input name="prodNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入生产令编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="proName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        部分
                                    </label>
                                    <label class="control-label">
                                        <input name="part" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入部分"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        类型
                                    </label>
                                    <label class="control-label">
                                        <select name="special" class="form-control">
                                            <option value="">全部</option>
                                            <option value="机械">机械</option>
                                            <option value="流体">流体</option>
                                            <option value="自动化">自动化</option>
                                            <option value="外观">外观</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        下料状态
                                    </label>
                                    <label class="control-label">
                                        <select name="cutStatus" class="form-control">
                                            <option value="">全部</option>
                                            <option value="0" selected="selected">待下料</option>
                                            <option value="1">已下料</option>
                                            <option value="2">不需要</option>
                                        </select>
                                    </label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar" class="row">
                    <button shiro:hasPermission="tran:laying:edit" onclick="operCutNecessarys()"
                            class="btn btn-warning">批量下料
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table;
    $(function () {
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "transposition/cutMaintain/list",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if (row.cutStatus === 2 || row.cutStatus === 1 ) {
                            return {disabled: true}
                        } else if(row.cutStatus === 0 || row.cutStatus === null) {
                            return {disabled: false}
                        }
                    }
                },
                {
                    title: '序号', field: 'orderNo', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '生产令编号', field: 'prodNo', width: '110',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'proName',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '数量', field: 'prodNum', width: '60',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '类型', field: 'special', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '部分', field: 'part', width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '下料状态', field: 'cutStatus', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 0) {
                                return '<label class="badge label-default">待下料</label>'
                            } else if (value === 1) {
                                return '<label class="badge label-success">已下料</label>'
                            } else if (value === 2) {
                                return '<label class="badge label-info">不需要</label>'
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '140',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (hasP('tran:laying:edit')) {
                            if (row.cutStatus === 0) {
                                elements.push('<button class="btn btn-warning btn-xs" onclick="operCutNecessary(\'' + row.prodNo + '\',\''+row.special+'\','+row.partId+')">下料</button>');
                            }
                            if (row.cutStatus === 0) {
                                elements.push('<button class="btn btn-info btn-xs" onclick="operCutUnwanted(\'' + row.prodNo + '\',\''+row.special+'\','+row.partId+')">不需要</button>');
                            }
                            if(row.cutStatus === 2){
                                elements.push('<button class="btn btn-success btn-xs" onclick="updateOperCut(\'' + row.prodNo + '\',\''+row.special+'\','+row.partId+')">需要</button>');
                            }
                        }
                        return elements.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });
    /**
     * 不需要下料
     */
    function operCutUnwanted(prodNo,special,partId) {
        js.confirmPost({
            content: "尊敬的用户，您确认要对此制作件清单执设置成不需要下料吗？",
            url: ctx + "transposition/cutMaintain/operCutUnwanted",
            data: {
                prodNo: prodNo,
                special:special,
                partId,partId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        });
    }
    /**
     * 还原下料不需要标识
     */
    function updateOperCut(prodNo,special,partId) {
        js.confirmPost({
            content: "确认需要吗？",
            url: ctx + "transposition/cutMaintain/updateOperCut",
            data: {
                prodNo: prodNo,
                special:special,
                partId,partId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        });
    }

    /**
     * 批量下料
     */
    function operCutNecessarys(){
        let prodNoArr = js.table.selectColumns(table, "prodNo");
        let specialArr = js.table.selectColumns(table, "special");
        let partIdArr = js.table.selectColumns(table, "partId");
        if (prodNoArr.length === 0) {
            js.modal.warning("尊敬的用户，请选择要下料的制作件清单！");
            return;
        } else {
            let cutArray = new Array();
            for (let i = 0; i < prodNoArr.length; i++) {
                let cutObject = new Object();
                cutObject.prodNo = prodNoArr[i];
                cutObject.special = specialArr[i];
                cutObject.partId = partIdArr[i];
                cutArray.push(cutObject);
            }
            js.confirmPost({
                content: "尊敬的用户，您确认要对此制作件清单执行下料吗？",
                url: ctx + "transposition/cutMaintain/operCutNecessarys",
                data: {
                    cutStr:JSON.stringify(cutArray)
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                }
            });
        }
    }
    /**
     * 需要下料
     */
    function operCutNecessary(prodNo,special,partId) {
        js.confirmPost({
            content: "尊敬的用户，您确认要对此制作件清单执行下料吗？",
            url: ctx + "transposition/cutMaintain/operCutNecessary",
            data: {
                prodNo: prodNo,
                special:special,
                partId,partId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        });
    }
</script>
</body>
</html>